package com.magoldeditor.util.xml;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;

import org.w3c.dom.Node;

import com.magoldeditor.model.IBody;
import com.magoldeditor.model.IJoint;

/**
 * 
 * @author Velconia
 * @version v.1.0
 * 
 */
public class ContentXMLWriter extends MaEditorXMLWriter implements IContentWriter{
	
	/**
	 * dafault root name
	 */
	private static final String ROOT_DEF = "MagoldMapData";
	
	/**
	 * default unity name
	 */
	private static final String UNITY = "!!unnamed unity!!";
	
	/**
	 * name
	 */
	private static final String NAME = "ContentXMLWriter";
	
	/**
	 * 
	 * @param fileName
	 * @throws FileNotFoundException
	 */
	public ContentXMLWriter(String fileName) throws FileNotFoundException {
		super(fileName);
		init();
	}
	
	/**
	 * 
	 * @param file
	 * @throws FileNotFoundException
	 */
	public ContentXMLWriter(File file) throws FileNotFoundException {
		super(file);
		init();
	}
	
	/**
	 * 
	 * @param fileOutputStream
	 */
	public ContentXMLWriter(FileOutputStream fileOutputStream) {
		super(fileOutputStream);
		init();
	}
	
	@Override
	public Node appendUnity(String unityName) {
		if (unityName != null) 
			return appendChild(this.document.getDocumentElement(), unityName);
		else 
			return appendChild(this.document.getDocumentElement(), UNITY);
	}

	@Override
	public void appendBody(Node unity, IBody body) {
		if (unity == null || body == null) {
			throw new RuntimeException(NAME + "the unity and body is null");
		} else {
			
		}
	}

	@Override
	public void appendJoint(Node unity, IJoint joint) {
		
	}
	
	@Override
	public void finalize() {
		
	}
	
	private void init() {
		this.setRoot(ROOT_DEF);
	}
}
